// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "FWFNavigationDelegateHostApi.h"
#import "FWFDataConverters.h"
#import "FWFURLAuthenticationChallengeHostApi.h"
#import "FWFWebViewConfigurationHostApi.h"

@interface FWFNavigationDelegateFlutterApiImpl ()
// BinaryMessenger must be weak to prevent a circular reference with the host API it
// references.
@property(nonatomic, weak) id<FlutterBinaryMessenger> binaryMessenger;
// InstanceManager must be weak to prevent a circular reference with the object it stores.
@property(nonatomic, weak) FWFInstanceManager *instanceManager;
@end

@implementation FWFNavigationDelegateFlutterApiImpl
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger
                        instanceManager:(FWFInstanceManager *)instanceManager {
  self = [self initWithBinaryMessenger:binaryMessenger];
  if (self) {
    _binaryMessenger = binaryMessenger;
    _instanceManager = instanceManager;
  }
  return self;
}

- (long)identifierForDelegate:(FWFNavigationDelegate *)instance {
  return [self.instanceManager identifierWithStrongReferenceForInstance:instance];
}

- (void)didFinishNavigationForDelegate:(FWFNavigationDelegate *)instance
                               webView:(WKWebView *)webView
                                   URL:(NSString *)URL
                            completion:(void (^)(FlutterError *_Nullable))completion {
  NSInteger webViewIdentifier =
      [self.instanceManager identifierWithStrongReferenceForInstance:webView];
  [self didFinishNavigationForDelegateWithIdentifier:[self identifierForDelegate:instance]
                                   webViewIdentifier:webViewIdentifier
                                                 URL:URL
                                          completion:completion];
}

- (void)didStartProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instance
                                         webView:(WKWebView *)webView
                                             URL:(NSString *)URL
                                      completion:(void (^)(FlutterError *_Nullable))completion {
  NSInteger webViewIdentifier =
      [self.instanceManager identifierWithStrongReferenceForInstance:webView];
  [self didStartProvisionalNavigationForDelegateWithIdentifier:[self identifierForDelegate:instance]
                                             webViewIdentifier:webViewIdentifier
                                                           URL:URL
                                                    completion:completion];
}

- (void)
    decidePolicyForNavigationActionForDelegate:(FWFNavigationDelegate *)instance
                                       webView:(WKWebView *)webView
                              navigationAction:(WKNavigationAction *)navigationAction
                                    completion:
                                        (void (^)(FWFWKNavigationActionPolicyEnumData *_Nullable,
                                                  FlutterError *_Nullable))completion {
  NSInteger webViewIdentifier =
      [self.instanceManager identifierWithStrongReferenceForInstance:webView];
  FWFWKNavigationActionData *navigationActionData =
      FWFWKNavigationActionDataFromNativeWKNavigationAction(navigationAction);
  [self
      decidePolicyForNavigationActionForDelegateWithIdentifier:[self identifierForDelegate:instance]
                                             webViewIdentifier:webViewIdentifier
                                              navigationAction:navigationActionData
                                                    completion:completion];
}

- (void)didFailNavigationForDelegate:(FWFNavigationDelegate *)instance
                             webView:(WKWebView *)webView
                               error:(NSError *)error
                          completion:(void (^)(FlutterError *_Nullable))completion {
  NSInteger webViewIdentifier =
      [self.instanceManager identifierWithStrongReferenceForInstance:webView];
  [self didFailNavigationForDelegateWithIdentifier:[self identifierForDelegate:instance]
                                 webViewIdentifier:webViewIdentifier
                                             error:FWFNSErrorDataFromNativeNSError(error)
                                        completion:completion];
}

- (void)didFailProvisionalNavigationForDelegate:(FWFNavigationDelegate *)instance
                                        webView:(WKWebView *)webView
                                          error:(NSError *)error
                                     completion:(void (^)(FlutterError *_Nullable))completion {
  NSInteger webViewIdentifier =
      [self.instanceManager identifierWithStrongReferenceForInstance:webView];
  [self didFailProvisionalNavigationForDelegateWithIdentifier:[self identifierForDelegate:instance]
                                            webViewIdentifier:webViewIdentifier
                                                        error:FWFNSErrorDataFromNativeNSError(error)
                                                   completion:completion];
}

- (void)webViewWebContentProcessDidTerminateForDelegate:(FWFNavigationDelegate *)instance
                                                webView:(WKWebView *)webView
                                             completion:
                                                 (void (^)(FlutterError *_Nullable))completion {
  NSInteger webViewIdentifier =
      [self.instanceManager identifierWithStrongReferenceForInstance:webView];
  [self webViewWebContentProcessDidTerminateForDelegateWithIdentifier:
            [self identifierForDelegate:instance]
                                                    webViewIdentifier:webViewIdentifier
                                                           completion:completion];
}

- (void)
    didReceiveAuthenticationChallengeForDelegate:(FWFNavigationDelegate *)instance
                                         webView:(WKWebView *)webView
                                       challenge:(NSURLAuthenticationChallenge *)challenge
                                      completion:
                                          (void (^)(FWFAuthenticationChallengeResponse *_Nullable,
                                                    FlutterError *_Nullable))completion {
  NSInteger webViewIdentifier =
      [self.instanceManager identifierWithStrongReferenceForInstance:webView];

  FWFURLAuthenticationChallengeFlutterApiImpl *challengeApi =
      [[FWFURLAuthenticationChallengeFlutterApiImpl alloc]
          initWithBinaryMessenger:self.binaryMessenger
                  instanceManager:self.instanceManager];
  [challengeApi createWithInstance:challenge
                   protectionSpace:challenge.protectionSpace
                        completion:^(FlutterError *error) {
                          NSAssert(!error, @"%@", error);
                        }];

  [self
      didReceiveAuthenticationChallengeForDelegateWithIdentifier:[self
                                                                     identifierForDelegate:instance]
                                               webViewIdentifier:webViewIdentifier
                                             challengeIdentifier:
                                                 [self.instanceManager
                                                     identifierWithStrongReferenceForInstance:
                                                         challenge]
                                                      completion:completion];
}
@end

@implementation FWFNavigationDelegate
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger
                        instanceManager:(FWFInstanceManager *)instanceManager {
  self = [super initWithBinaryMessenger:binaryMessenger instanceManager:instanceManager];
  if (self) {
    _navigationDelegateAPI =
        [[FWFNavigationDelegateFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger
                                                             instanceManager:instanceManager];
  }
  return self;
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
  [self.navigationDelegateAPI didFinishNavigationForDelegate:self
                                                     webView:webView
                                                         URL:webView.URL.absoluteString
                                                  completion:^(FlutterError *error) {
                                                    NSAssert(!error, @"%@", error);
                                                  }];
}

- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
  [self.navigationDelegateAPI didStartProvisionalNavigationForDelegate:self
                                                               webView:webView
                                                                   URL:webView.URL.absoluteString
                                                            completion:^(FlutterError *error) {
                                                              NSAssert(!error, @"%@", error);
                                                            }];
}

static NSString *payReturnUrl;//支付返回页面

- (void)webView:(WKWebView *)webView
    decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction
                    decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    [self.navigationDelegateAPI
        decidePolicyForNavigationActionForDelegate:self
                                           webView:webView
                                  navigationAction:navigationAction
                                        completion:^(FWFWKNavigationActionPolicyEnumData *policy,
                                                     FlutterError *error) {
    NSURL *requestURL =  navigationAction.request.URL;
    //设置微信支付跳转问题
    //易联盟生产
    NSString *chinaumsUrl = @"qr.chinaums.com";
    NSString *chinaumsRedirectUrl = @"eshore.qr.chinaums.com://";

    //cmpark生产
    NSString *cmparkUrl = @"app.park.cmskcrm.com";
    NSString *cmparkRedirectUrl = @"eshore.app.park.cmskcrm.com://";
    //cmpark测试
    NSString *cmparkTestUrl = @"app.park.ylmo2o.com";
    NSString *cmparkTestRedirectUrl = @"eshore.app.park.ylmo2o.com://";

    NSString *urlString = requestURL.absoluteString;
    urlString = [urlString stringByRemovingPercentEncoding];

    if ([urlString hasPrefix:@"https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb"]) { // 处理微信支付返回APP问题
        NSString *newRedirectUrl;//返回地址

        //易联盟的支付（物管交费）
        NSRange range=[urlString rangeOfString:chinaumsUrl];
        if(range.location!=NSNotFound){
            newRedirectUrl = chinaumsRedirectUrl;
        }

        //cmpark的生产支付（停车办理，临停缴费）
        range=[urlString rangeOfString:cmparkUrl];
        if(range.location!=NSNotFound){
            newRedirectUrl = cmparkRedirectUrl;
        }
        //cmpark的测试支付（停车办理，临停缴费）
        range=[urlString rangeOfString:cmparkTestUrl];
        if(range.location!=NSNotFound){
            newRedirectUrl = cmparkTestRedirectUrl;
        }

        //需要跳转回APP
        if(newRedirectUrl!=NULL){
            //判断是否已经添加过返回跳转地址
            range=[urlString rangeOfString:newRedirectUrl];
            if(range.location==NSNotFound){
                urlString = [urlString stringByReplacingOccurrencesOfString:@"redirect_url=" withString:[@"redirect_url=" stringByAppendingString:newRedirectUrl]];
            }
            //设置返回的加载页面
            range=[urlString rangeOfString:newRedirectUrl];
            if(range.location!=NSNotFound){
                payReturnUrl = [urlString substringFromIndex:range.location+newRedirectUrl.length];
                payReturnUrl = [payReturnUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            }
            urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            requestURL = [NSURL URLWithString:urlString];
            NSDictionary *header = navigationAction.request.allHTTPHeaderFields;
            if (header[@"Referer"] && [header[@"Referer"] isEqualToString:newRedirectUrl]) { // 如果已经设置过referer
                // 允许跳转
                decisionHandler(WKNavigationActionPolicyAllow);
                return;
            } else {
                //                 设置referer
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

                    dispatch_async(dispatch_get_main_queue(), ^{
                        NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:requestURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
                        [request setHTTPMethod:@"GET"];
                        [request setValue:newRedirectUrl forHTTPHeaderField: @"Referer"];
                        [webView loadRequest:request];
                    });
                });
                decisionHandler(WKNavigationActionPolicyCancel);
                return;
            }
        }else{
            NSLog(@"%@", @"未适配的支付");
            NSLog(@"%@", requestURL.absoluteString);
        }
    }else if ([urlString hasPrefix:chinaumsRedirectUrl]
              ||[urlString hasPrefix:cmparkRedirectUrl]
              ||[urlString hasPrefix:cmparkTestRedirectUrl]) {
        //微信支付跳转返回的页面
        NSString *loadUrl= urlString;
        //已经适配的微信支付跳转返回的页面
        if(payReturnUrl!=NULL){
            loadUrl = payReturnUrl;
            payReturnUrl =NULL;
        }

        loadUrl = [loadUrl stringByReplacingOccurrencesOfString:chinaumsRedirectUrl withString:@""];
        loadUrl = [loadUrl stringByReplacingOccurrencesOfString:cmparkRedirectUrl withString:@""];
        loadUrl = [loadUrl stringByReplacingOccurrencesOfString:cmparkTestRedirectUrl withString:@""];

        loadUrl = [loadUrl  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        requestURL = [NSURL URLWithString:loadUrl];
        NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:requestURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
        [request setHTTPMethod:@"GET"];
        [webView loadRequest:request];

        decisionHandler(WKNavigationActionPolicyCancel);
        return;
    }
    if (requestURL != nil) {
        if ([requestURL.scheme isEqualToString:@"weixin"]) {    //处理微信支付
            [self weixinCatchEvent:requestURL];
            decisionHandler(WKNavigationActionPolicyCancel);
            return;
        } else if ([requestURL.scheme isEqualToString:@"alipays"] || [requestURL.scheme isEqualToString:@"alipay"]) {       //处理支付宝支付
            [self zhifubaoCatchEvent:requestURL];
        } else if ([requestURL.scheme isEqualToString:@"uppaywallet"] || [requestURL.scheme isEqualToString:@"uppaysdk"]) {       //处理翼支付支付
            [self yunshanfuCatchEvent:requestURL];
        } else if ([requestURL.scheme isEqualToString:@"intent"]) {
            if ([requestURL.host isEqualToString:@"platformapi"] && [requestURL.relativePath isEqualToString:@"/startapp"]) {       //处理老版本支付宝支付
                [self zhifubaoCatchEvent:requestURL];
            }
        }
    }

    NSString *_webUrlStr = navigationAction.request.URL.absoluteString;
    NSString *lastName =[[_webUrlStr lastPathComponent] lowercaseString];
    if ([lastName containsString:@".pdf"])
    {
        NSData *data = [NSData dataWithContentsOfURL:navigationAction.request.URL];
        [webView loadData:data MIMEType:@"application/pdf" characterEncodingName:@"GBK" baseURL:nil];
    }

    BOOL isInvalid = [self checkInvalidUrl: navigationAction.request.URL];
    
    id data = @{@"url": navigationAction.request.URL.absoluteString,
                @"type": isInvalid ? @"abortLoad" : @"shouldStart",
                @"navigationType": [NSNumber numberWithInteger:navigationAction.navigationType]};
    [channel invokeMethod:@"onState" arguments:data];

    if (navigationAction.navigationType == WKNavigationTypeBackForward) {
        [channel invokeMethod:@"onBackPressed" arguments:nil];
    } else if (!isInvalid) {
        id data = @{@"url": navigationAction.request.URL.absoluteString};
        [channel invokeMethod:@"onUrlChanged" arguments:data];
    }

    if (_enableAppScheme ||
        ([webView.URL.scheme isEqualToString:@"http"] ||
         [webView.URL.scheme isEqualToString:@"https"] ||
         [webView.URL.scheme isEqualToString:@"about"] ||
         [webView.URL.scheme isEqualToString:@"file"])) {
         if (isInvalid) {
            decisionHandler(WKNavigationActionPolicyCancel);
         } else {
            decisionHandler(WKNavigationActionPolicyAllow);
         }
    } else {
        decisionHandler(WKNavigationActionPolicyCancel);
    }
  
//    NSAssert(!error, @"%@", error);
//    if (!error) {
//      decisionHandler(
//          FWFNativeWKNavigationActionPolicyFromEnumData(
//              policy));
//    } else {
//      decisionHandler(WKNavigationActionPolicyCancel);
//    }
  }];
}

- (void)weixinCatchEvent:(NSURL *)url {
    if ([url.host isEqualToString:@"wap"]) {
        if ([url.relativePath isEqualToString:@"/pay"]) {
            if ([[UIApplication sharedApplication] canOpenURL:url]) {
                if ( @available(iOS 10.0, *) ) {
                    [[UIApplication sharedApplication] openURL:url options:@{UIApplicationOpenURLOptionUniversalLinksOnly : [NSNumber numberWithBool:NO]} completionHandler:^(BOOL success) {

                    }];
                } else {
                    [[UIApplication sharedApplication] openURL:url];
                }
            } else {
                NSString *title = @"未检测到微信，请安装后重试";
                [self showAlertController:[UIApplication sharedApplication].keyWindow.rootViewController title:title message:nil cancelTilte:@"好" otherTitleArray:nil];
            }
        }
    }
}

- (void)zhifubaoCatchEvent:(NSURL *)url {
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        if ( @available(iOS 10.0, *) ) {
            [[UIApplication sharedApplication] openURL:url options:@{UIApplicationOpenURLOptionUniversalLinksOnly : [NSNumber numberWithBool:NO]} completionHandler:^(BOOL success) {

            }];
        } else {
            [[UIApplication sharedApplication] openURL:url];
        }
    } else {
        // 下面两行代码 是修改 title颜色和字体的代码
        NSString *title = @"未检测到支付宝，请安装后重试";
        [self showAlertController:[UIApplication sharedApplication].keyWindow.rootViewController title:title message:nil cancelTilte:@"好" otherTitleArray:nil];
    }
}

- (void)yunshanfuCatchEvent:(NSURL *)url {
  NSLog(@"yunshanfuCatchEvent:%@", url);
  
  // Check if the app is actually installed using application state monitoring
  __block BOOL didEnterBackground = NO;
  
  // Set up notification to detect if app enters background (meaning the other app opened)
  id observer = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidEnterBackgroundNotification 
    object:nil 
    queue:[NSOperationQueue mainQueue] 
    usingBlock:^(NSNotification *note) {
      didEnterBackground = YES;
    }];
  
  // Set a timer to check if we actually left our app
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    // Remove the observer
    [[NSNotificationCenter defaultCenter] removeObserver:observer];
    
    // If we didn't enter background, the app didn't open
    if (!didEnterBackground) {
      NSLog(@"App did not enter background - showing alert");
      NSString *title = @"未检测到云闪付，请安装后重试";
      [self showAlertController:[UIApplication sharedApplication].keyWindow.rootViewController title:title message:nil cancelTilte:@"好" otherTitleArray:nil];
    }
  });
  
  // Try to open the URL
  if (@available(iOS 10.0, *)) {
    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  } else {
    [[UIApplication sharedApplication] openURL:url];
  }
}

//alert封装
- (void)showAlertController:(UIViewController *)viewController
                      title:(NSString *)title
                    message:(NSString *)message
                cancelTilte:(NSString *)cancelTitle
            otherTitleArray:(NSArray *)otherTitleArray {

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];

    // 下面两行代码 是修改 title颜色和字体的代码
    NSAttributedString *attributedMessage = [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10.0f], NSForegroundColorAttributeName:[UIColor blackColor]}];
    [alert setValue:attributedMessage forKey:@"attributedTitle"];
    if (cancelTitle) {
        // 取消
        UIAlertAction  *cancelAction = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

        }];
        [alert addAction:cancelAction];
    }

    if (otherTitleArray.count>0) {
        for (NSInteger i = 0; i<otherTitleArray.count; i++) {

            UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherTitleArray[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            }];
            // [action setValue:[UIColor redColor] forKey:@"titleTextColor"]; // 此代码 可以修改按钮颜色
            [alert addAction:otherAction];
        }

    }

    [viewController presentViewController:alert animated:YES completion:nil];

}

- (bool)checkInvalidUrl:(NSURL*)url {
  NSString* urlString = url != nil ? [url absoluteString] : nil;
  if (_invalidUrlRegex != nil && ![_invalidUrlRegex isEqual:[NSNull null]] && urlString != nil) {
    NSError* error = NULL;
    NSRegularExpression* regex =
        [NSRegularExpression regularExpressionWithPattern:_invalidUrlRegex
                                                  options:NSRegularExpressionCaseInsensitive
                                                    error:&error];
    NSTextCheckingResult* match = [regex firstMatchInString:urlString
                                                    options:0
                                                      range:NSMakeRange(0, [urlString length])];
    return match != nil;
  } else {
    return false;
  }
}

- (void)webView:(WKWebView *)webView
    didFailNavigation:(WKNavigation *)navigation
            withError:(NSError *)error {
  [self.navigationDelegateAPI didFailNavigationForDelegate:self
                                                   webView:webView
                                                     error:error
                                                completion:^(FlutterError *error) {
                                                  NSAssert(!error, @"%@", error);
                                                }];
}

- (void)webView:(WKWebView *)webView
    didFailProvisionalNavigation:(WKNavigation *)navigation
                       withError:(NSError *)error {
  [self.navigationDelegateAPI didFailProvisionalNavigationForDelegate:self
                                                              webView:webView
                                                                error:error
                                                           completion:^(FlutterError *error) {
                                                             NSAssert(!error, @"%@", error);
                                                           }];
}

- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
  [self.navigationDelegateAPI
      webViewWebContentProcessDidTerminateForDelegate:self
                                              webView:webView
                                           completion:^(FlutterError *error) {
                                             NSAssert(!error, @"%@", error);
                                           }];
}

- (void)webView:(WKWebView *)webView
    didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
                    completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition,
                                                NSURLCredential *_Nullable))completionHandler {
  [self.navigationDelegateAPI
      didReceiveAuthenticationChallengeForDelegate:self
                                           webView:webView
                                         challenge:challenge
                                        completion:^(FWFAuthenticationChallengeResponse *response,
                                                     FlutterError *error) {
                                          NSAssert(!error, @"%@", error);
                                          if (!error) {
                                            NSURLSessionAuthChallengeDisposition disposition =
                                                FWFNativeNSURLSessionAuthChallengeDispositionFromFWFNSUrlSessionAuthChallengeDisposition(
                                                    response.disposition);

                                            NSURLCredential *credential =
                                                response.credentialIdentifier
                                                    ? (NSURLCredential *)[self.navigationDelegateAPI
                                                                              .instanceManager
                                                          instanceForIdentifier:
                                                              response.credentialIdentifier
                                                                  .longValue]
                                                    : nil;

                                            completionHandler(disposition, credential);
                                          } else {
                                            completionHandler(
                                                NSURLSessionAuthChallengeCancelAuthenticationChallenge,
                                                nil);
                                          }
                                        }];
}
@end

@interface FWFNavigationDelegateHostApiImpl ()
// BinaryMessenger must be weak to prevent a circular reference with the host API it
// references.
@property(nonatomic, weak) id<FlutterBinaryMessenger> binaryMessenger;
// InstanceManager must be weak to prevent a circular reference with the object it stores.
@property(nonatomic, weak) FWFInstanceManager *instanceManager;
@end

@implementation FWFNavigationDelegateHostApiImpl
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger
                        instanceManager:(FWFInstanceManager *)instanceManager
                                channelData:(FlutterMethodChannel *)channelData
                            invalidUrlRegex:(NSString *)invalidUrlRegex
                            enableAppScheme:(BOOL *)enableAppScheme {
  self = [self init];
  if (self) {
    _binaryMessenger = binaryMessenger;
    _instanceManager = instanceManager;
      channel = channelData;
      _invalidUrlRegex = invalidUrlRegex;
      _enableAppScheme = enableAppScheme;
  }
  return self;
}

- (FWFNavigationDelegate *)navigationDelegateForIdentifier:(NSInteger)identifier {
  return (FWFNavigationDelegate *)[self.instanceManager instanceForIdentifier:identifier];
}

- (void)createWithIdentifier:(NSInteger)identifier
                       error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
  FWFNavigationDelegate *navigationDelegate =
      [[FWFNavigationDelegate alloc] initWithBinaryMessenger:self.binaryMessenger
                                             instanceManager:self.instanceManager];
  [self.instanceManager addDartCreatedInstance:navigationDelegate withIdentifier:identifier];
}
@end
